home *** CD-ROM | disk | FTP | other *** search
/ Windows 3-Pak 2 - Disc 2 / Infomagic - Windows 3-Pak Volume 2 (Disc 2 of 3).iso / Chat---IRC / TURBOIRC.ZIP / data1.cab / TurboIRC_Scripts / ASM.txt < prev    next >
Text File  |  1999-05-05  |  7KB  |  342 lines

  1. // Mail HTML Script for TurboIRC
  2. #debug
  3.  
  4. // Change these parameters 
  5. #define MYNAME Michael
  6. #define MYMAIL xmic@freemail.gr
  7. #define PRIORITY 9
  8.  
  9. if ("$1"!="")
  10.  goto whandle
  11. endif
  12.  
  13. HTML_Load()
  14.  
  15. // Get MailServer
  16. string MailServ = GetString("General","MailServer","","C:\\TURBOIRC\\PREF.INI")
  17.  
  18. string V = sprintf("%s;%s",MailServ,"25")
  19. // Show HTML
  20. HTML_SetArgs(V)
  21. HTML_Show("file://C:\\TURBOIRC\\SCRIPTS\\MAIL.HTM")
  22. V = HTML_GetArgs()
  23.  
  24. HTML_Free()
  25.  
  26. if (V=="")
  27.  return
  28. endif
  29.  
  30. string _Server = GetParameter(0,V)
  31. string _Port = GetParameter(1,V)
  32. staticstring _To = GetParameter(2,V)
  33. staticstring _Subject = GetParameter(3,V)
  34. staticstring _Attach = GetParameter(4,V)
  35. staticstring _Message = GetZParameter(5,V)
  36.  
  37. int PP = atoi(_Port)
  38.  
  39. // Now the dirty work
  40. staticint sss = socket(1)
  41. staticint m_stat = 0
  42. if (connect(sss,_Server,PP)!=0)
  43.  goto Err
  44. endif
  45.  
  46. // Create the window
  47. int hPar = GetWOPTIONS($servernumber,"Frame")
  48. staticint m_hWnd = CreateWindow(1808,"frame","Mailing...",281735168,50,50,311,250,hPar,0,16744576)
  49.  
  50. // ListBox
  51. CreateWindow(0,"listbox","",1350631424,0,0,311,250,m_hWnd,101,0)
  52.  
  53. SetWindowHandler(m_hWnd,33000,-1,-1,"ASM")
  54.  
  55.  
  56. // FD_READ
  57. WSAAsyncSelect(sss,m_hWnd,33000,1) 
  58.  
  59. return
  60.  
  61.  
  62.  
  63. :whandle
  64.  
  65.  
  66. string _ToSend = ""
  67. int _SendL = 0
  68.  
  69.  
  70. if (m_stat==5)
  71.  goto Stat5
  72. endif
  73. if (m_stat==4)
  74.  m_stat = 5 ; the status will manage it
  75.  goto Stat4
  76. endif
  77. if (m_stat==3)
  78.  m_stat = 4
  79.  goto Stat3
  80. endif
  81. if (m_stat==2)
  82.  m_stat = 3
  83.  goto Stat2
  84. endif
  85. if (m_stat==1)
  86.  m_stat = 2
  87.  goto Stat1
  88. endif
  89. if (m_stat==0)
  90.  m_stat = 1
  91.  goto Stat0
  92. endif
  93.  
  94.  
  95. // Status 0
  96. :Stat0
  97. // Receive Answer
  98. _ToSend = recv(sss,1000,0)
  99. if (WSAGetLastError()==10035)
  100.  return
  101. endif
  102. if (strncmp(_ToSend,"2",1)!=0)
  103.  goto Err
  104. endif
  105.  
  106.  
  107. // Send HELO , MAIL , RCPT 
  108. SendMessage(GetDlgItem(m_hWnd,101),384,-1,"Connected.")
  109. _ToSend = "HELO there"
  110. _ToSend = AddCRLF(_ToSend)
  111. _SendL = strlen(_ToSend)
  112. send(sss,_ToSend,_SendL,0)
  113.  
  114.  
  115. // Status 1
  116. :Stat1
  117. // Receive Answer
  118. _ToSend = recv(sss,1000,0)
  119. if (WSAGetLastError()==10035)
  120.  return
  121. endif
  122. if (strncmp(_ToSend,"2",1)!=0)
  123.  goto err
  124. endif
  125.  
  126. // MAIL FROM
  127. SendMessage(GetDlgItem(m_hWnd,101),384,-1,"Sending sender...")
  128. _ToSend = "MAIL FROM:<xmic@freemail.gr>"
  129. _ToSend = AddCRLF(_ToSend)
  130. _SendL = strlen(_ToSend)
  131. send(sss,_ToSend,_SendL,0)
  132.  
  133. // Status 2
  134. :Stat2
  135. // Receive Answer
  136. _ToSend = recv(sss,1000,0)
  137. if (WSAGetLastError()==10035)
  138.  return
  139. endif
  140. if (strncmp(_ToSend,"2",1)!=0)
  141.  goto Err
  142. endif
  143.  
  144. // RCPT TO
  145. SendMessage(GetDlgItem(m_hWnd,101),384,-1,"Sending receipient...")
  146. _ToSend = sprintf("RCPT TO:<%s>",_To)
  147. _ToSend = AddCRLF(_ToSend)
  148. _SendL = strlen(_ToSend)
  149. send(sss,_ToSend,_SendL,0)
  150.  
  151. // Status 3
  152. :Stat3
  153. // Receive Answer
  154. _ToSend = recv(sss,1000,0)
  155. if (WSAGetLastError()==10035)
  156.  return
  157. endif
  158. if (strncmp(_ToSend,"2",1)!=0)
  159.  goto Err
  160. endif
  161.  
  162. // DATA
  163. SendMessage(GetDlgItem(m_hWnd,101),384,-1,"Sending data request...")
  164. _ToSend = "DATA"
  165. _ToSend = AddCRLF(_ToSend)
  166. _SendL = strlen(_ToSend)
  167. send(sss,_ToSend,_SendL,0)
  168.  
  169. // Status 4
  170. :Stat4
  171. // Receive Answer
  172. _ToSend = recv(sss,1000,0)
  173. if (WSAGetLastError()==10035)
  174.  return
  175. endif
  176. if (strncmp(_ToSend,"354",3)!=0)
  177.  goto Err
  178. endif
  179.  
  180. // Send message heh
  181. SendMessage(GetDlgItem(m_hWnd,101),384,-1,"Sending message...")
  182.  
  183. // Format message
  184. // Formula
  185. // 1 : Header in MAIL_1.hdr
  186. // 2 : Subject attach
  187. // 3 : Rest Header in MAIL_2.hdr
  188. // 4 : Message
  189. // 5 : Delimiter in MAIL_3.hdr
  190. // 6 : Attachment encoded
  191. // 7 : Delimiter in MAIL_3.hdr
  192.  
  193.  
  194. staticstring _mfile = CreateTemporaryFile()
  195. string _CRLF = ""
  196. string _QT = """
  197. string _TMP = ""
  198. _CRLF = AddCRLF(_CRLF)
  199.  
  200. AppendTextCRLF(_mfile,"Message-ID: <44TurboIRC0005MailScript>")
  201. AppendTextCRLF(_mfile,"From: "MYNAME" <MYMAIL>")
  202. AppendTextCRLF(_mfile,"To: "TurboIRC Mail Script Transfer" ")
  203.  
  204. _TMP = sprintf("Subject : %s\r\n",_Subject)
  205. AppendText(_mfile,_TMP)
  206.  
  207. AppendTextCRLF(_mfile,"MIME-Version: 1.0")
  208. AppendTextCRLF(_mfile,"X-Priority: PRIORITY")
  209. AppendTextCRLF(_mfile,"X-Mailer: TurboIRC 98 IRCX Client by Chourdakis Michael (xmic@freemail.gr) - Mail Script")
  210. AppendTextCRLF(_mfile,"Content-Type: multipart/mixed;")
  211. AppendTextCRLF(_mfile,"\tboundary=\x22----=_NextPart_000_TurboIRC\x22")
  212. AppendTextCRLF(_mfile,"X-MimeOLE: Produced by TurboIRC 98")
  213. AppendText(_mfile,_CRLF)
  214. AppendText(_mfile,_CRLF)
  215.  
  216. AppendTextCRLF(_mfile,"This is a multi-part message in MIME format.")
  217. AppendText(_mfile,_CRLF)
  218. AppendText(_mfile,_CRLF)
  219.  
  220. // Message
  221.  
  222. AppendTextCRLF(_mfile,"------=_NextPart_000_TurboIRC")
  223. AppendTextCRLF(_mfile,"Content-Type: text/plain;")
  224. AppendTextCRLF(_mfile,"\tcharset=\x22iso-8859-7\x22")
  225. AppendTextCRLF(_mfile,"Content-Transfer-Encoding: 7bit")
  226. AppendText(_mfile,_CRLF)
  227. AppendText(_mfile,_CRLF)
  228.  
  229. AppendText(_mfile,_Message)
  230. AppendText(_mfile,_CRLF)
  231. AppendText(_mfile,_CRLF)
  232. AppendText(_mfile,_CRLF)
  233.  
  234. AppendTextCRLF(_mfile,"------=_NextPart_000_TurboIRC")
  235.  
  236. if (_Attach!="*")
  237.  // attach also
  238.  string vf = CreateTemporaryFile()
  239.  string vw = FullToShort(_Attach)
  240.  
  241.  FileToBase64(_Attach,vf)
  242.  //AppendTextCRLF(_mfile,"Content-Type: application/octet-stream;")
  243.  
  244.  _TMP = sprintf("Content-Type: application/octet-stream; name=\x22%s\x22\r\n",vw)
  245.  AppendText(_mfile,_TMP)
  246.  
  247.  AppendTextCRLF(_mfile,"Content-Transfer-Encoding: base64")
  248.  
  249.  AppendTextCRLF(_mfile,"Content-Disposition: attachment;")
  250.  _TMP = sprintf("Content-Disposition: attachment; filename=\x22%s\x22\r\n",vw)
  251.  
  252.  AppendText(_mfile,_TMP)
  253.  
  254.  AppendText(_mfile,_CRLF)
  255.  AppendText(_mfile,_CRLF)
  256.  AppendFile(_mfile,vf)
  257.  AppendText(_mfile,_CRLF)
  258.  AppendText(_mfile,_CRLF)
  259.  AppendTextCRLF(_mfile,"------=_NextPart_000_TurboIRC")
  260.  DeleteFile(vf)
  261. endif
  262.  
  263. AppendText(_mfile,_CRLF)
  264. AppendText(_mfile,_CRLF)
  265. AppendText(_mfile,_CRLF)
  266. AppendText(_mfile,".")
  267. AppendText(_mfile,_CRLF)
  268.  
  269.  
  270. // Now _mfile has the mail to be sent !
  271.  
  272. int fLen = GetFileSize(_mfile);
  273. int hFile = CreateFile(_mfile,0,3)
  274. if (hFile==-1)
  275.  goto Err
  276. endif
  277.  
  278. SetFilePointer(hFile,0,0);
  279.  
  280. int zz = 0
  281. string ReadHere = ""
  282. int SizeSent = 0
  283.  
  284. for (SizeSent = 0 ; SizeSent < fLen ; )
  285.  ReadHere = ReadFile(hFile,100) 
  286.  zz = fLen - SizeSent
  287.  if (zz > 100)
  288.   SizeSent += send(sss,ReadHere,100,0)
  289.  else
  290.   SizeSent += send(sss,ReadHere,zz,0)
  291.   break
  292.  endif
  293.  // Update File Pointer based to SizeSent
  294.  SetFilePointer(hFile,SizeSent,0)
  295. endfor
  296.  
  297. CloseFile(hFile)
  298.  
  299.  
  300.  
  301. // Status 5
  302. :Stat5
  303. // Receive Answer
  304. _ToSend = recv(sss,1000,0)
  305. if (WSAGetLastError()==10035)
  306.  return
  307. endif
  308. if (strncmp(_ToSend,"2",1)!=0)
  309.  goto Err
  310. endif
  311.  
  312. // Terminate
  313. closesocket(sss)
  314. DestroyWindow(m_hWnd)
  315. //DeleteFile(_mfile)
  316. /destroystaticvariable m_hWnd
  317. /destroystaticvariable sss
  318. /destroystaticvariable m_stat
  319. /destroystaticvariable _To
  320. /destroystaticvariable _Message
  321. /destroystaticvariable _Subject
  322. /destroystaticvariable _Attach
  323. /destroystaticvariable _mfile
  324.  
  325.  
  326. /addtext ! 4***Mail sent successfully !!
  327. return
  328.  
  329. :Err
  330. closesocket(sss)
  331. DestroyWindow(m_hWnd)
  332. //DeleteFile(_mfile)
  333. /destroystaticvariable m_hWnd
  334. /destroystaticvariable sss
  335. /destroystaticvariable _To
  336. /destroystaticvariable _Message
  337. /destroystaticvariable _Subject
  338. /destroystaticvariable _Attach
  339. /destroystaticvariable m_stat
  340. /destroystaticvariable _mfile
  341. /addtext ! SendMail failed !
  342.